import 'package:flutter/material.dart';
import 'package:leader_help/page/home/key_point/key_point_view.dart';
import 'package:leader_help/page/home/key_task/key_task_view.dart';
import 'package:leader_help/page/home/key_think_tank/key_think_tank_view.dart';
import 'package:leader_help/page/home/main/models/first_site.dart';
import 'package:leader_help/utils/component/dialog/drop.dart';
import 'package:leader_help/utils/util.dart';
import 'package:get/get.dart';

import 'index.dart';

class HomeController extends GetxController
    with GetSingleTickerProviderStateMixin {
  HomeController();

  final state = HomeState();

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    state.tabCtrl = TabController(length: 5, vsync: this)
      ..addListener(() {
        update();
      });
    super.onInit();

    // state.scrollCtrl.addListener(() {
    //   var off = state.scrollCtrl.offset;
    //   if (off >= SizeFit.statusBarHeight) {
    //     if (!state.isShowInfo) {
    //       state.isShowInfo = true;
    //       update();
    //     }
    //   } else {
    //     if (state.isShowInfo) {
    //       state.isShowInfo = false;
    //       update();
    //     }
    //   }
    // });

    state.headlinesBanner = [
      'headlines_banner_01.jpg'.imgPathHome,
      'headlines_banner_02.jpg'.imgPathHome,
      'headlines_banner_03.jpg'.imgPathHome,
      'headlines_banner_04.jpg'.imgPathHome,
    ];
    state.headlinesTitles = ['推荐', '中央领导', '各省领导', '中央部委机关', '本省'];
    state.firstSiteList = [
      FirstSiteModel(
        title: '中原科技城--国家技术转移郑州中心建设项目',
        picUrl: 'firstSite_01.jpeg'.imgPathHome,
      ),
      FirstSiteModel(
        title: '中原科技城--中原动力智能机器人研发中心',
        picUrl: 'firstSite_02.jpeg'.imgPathHome,
      )
    ];
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    state.slogans.value = ['高质量发展', '数字化改革', '实体创新', '数字倍增', '中国必由之路'];
    state.headerMenu = [
      UsuallyModel(
          name: '关键任务', iconData: ProIconUtil.target_1, onTap: actionKeyTask),
      UsuallyModel(
          name: '我的重点', iconData: ProIconUtil.task, onTap: actionKeyTask1),
      UsuallyModel(
          name: '区域竞争', iconData: ProIconUtil.area, onTap: actionKeyTask2),
      UsuallyModel(
          name: '国家智库', iconData: ProIconUtil.expert, onTap: actionKeyTask3)
    ];
    update();
    super.onReady();
  }

  void actionKeyTask() {
    Get.to(const KeyTaskPage());
  }

  void actionKeyTask1() {
    Get.to(const KeyPointPage());
  }

  void actionKeyTask2() {
    Get.toNamed(RouterPath.area_compete);
  }

  void actionKeyTask3() {
    Get.to(const KeyThinkTankPage());
  }

  void actionHeadlinesMore() {
    Get.toNamed(RouterPath.headlines);
  }

  void actionHeadlinesDetail() {
    Get.toNamed(RouterPath.news_detail);
  }

  void actionVideo(FirstSiteModel mod) {
    Get.toNamed(RouterPath.video_detail, arguments: mod);
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
